import WebSocketClient from './websocket';
/**
 * WebSocket 配置选项
 */
interface WebSocketConfig {
  url: string;
  heartbeatInterval?: number;
  heartbeatMessage?: string | object;
  reconnectInterval?: number;
  maxReconnectAttempts?: number;
}
/**
 * 初始化 WebSocket 连接
 * 在应用启动时调用一次
 */
export function initWebSocket(config: WebSocketConfig): WebSocketClient {
  const wsClient = WebSocketClient.getInstance({
    url: config.url,
    heartbeatInterval: config.heartbeatInterval,
    heartbeatMessage: config.heartbeatMessage,
    reconnectInterval: config.reconnectInterval,
    maxReconnectAttempts: config.maxReconnectAttempts,
  });
  return wsClient;
}

/**
 * 在任意组件中获取 WebSocket 实例
 */
export function getWebSocketInstance(): WebSocketClient {
  return WebSocketClient.getInstance({
    url: '', // 这里传空字符串，因为实例已经存在，不会创建新的连接
  });
}
/*
// 在应用入口初始化
const wsConfig = {
  url: 'ws://your-websocket-server.com/ws',
  heartbeatInterval: 30000,
  heartbeatMessage: { type: 'heartbeat', data: 'ping' },
  reconnectInterval: 3000,
  maxReconnectAttempts: 5
};

const wsClient = initWebSocket(wsConfig);
// 在组件中使用
const ws = getWebSocketInstance();
ws.on('message', (data) => {
  console.log('收到消息:', data);
});
*/ 